/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utilities;

import java.util.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.*;

/**
 *
 * @author Phuong Giang
 */
class ExpireCheckingTask extends TimerTask {

    private long expire;
    private Collection<File> fileList;

    public ExpireCheckingTask(long expire, Collection<File> fileList) {
        this.expire = expire;
        this.fileList = fileList;
    }

    @Override
    public void run() {
        // job code here
        System.out.println(new Date());
        for (File f : fileList) {
            if (FileUtils.isFileOlder(f, new Date().getTime() - expire)) {
                try {
                    FileUtils.forceDelete(f);
                    System.out.println("deleted");
                } catch (IOException ex) {
                    Logger.getLogger(ExpireCheckingTask.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
                }
            }
        }
    }
}